<?php

# Defaults
$TransmissionResultCode = 1;

# Required Alterar para ficheiro de transact na pasta queries

$TrsID = $TrnID;
$TrnTime = $sysTime;

if ($TransmissionResultCode == 1) {

    $CorrProperties = $GLOBALS['MYT']->db_array("SELECT CorrNumero, CorrFormatoFichero, CorrAgente FROM corresponsales WHERE CorrAgente = '{$GETCOMMETH[1]['CorrAgente']}'");
    # Verifica repeticoes de lote
    $CorrExpectedTransaction = $GLOBALS['MYT']->db_array("SELECT Trs_CorrTrans AS NextExpected FROM transmitions WHERE Trs_ID = $TrsID");
    if (isset($CorrExpectedTransaction[1]) && isset($GetMethodParams[1])) {
        $TransactionFTName = transaction_filenames($DatadirTransmitionOut, $TrnTime, $CorrExpectedTransaction[1]['NextExpected'], $CorrProperties[1]['CorrAgente'], $GetMethodParams[1]['ffFilenameFormat'], $GetMethodParams[1]['EXT']);
        $TransactionModel = $TFTPATH_MODELS . $GetMethodParams[1]['DELIMITER'] . '_' . $GetMethodParams[1]['EXT'] . '_' . $GetMethodParams[1]['OB'] . '_' . $GetMethodParams[1]['VERSION'] . '_' . $PID . '.php';
        if ($this->tft_OutputFile($TransactionModel,$DatadirTransmitionOut . $TransactionFTName, $this->sql_GetTransactionRows($PID,$CorrespID,$TrnAffected), $CNC) == true) {
            $TransmissionResultCode = 2;
            ## if active ftp transact
            if (isset($GETCOMMETH[1])) {
                ## copia ficheiro para pasta ftp
                if(is_dir($GetSettings[1]['set_Valor'] . '//' . $GETCOMMETH[1]['CorrAgente'] . '//OUT//')){
                if (!copy($DatadirTransmitionOut . $TransactionFTName, $GetSettings[1]['set_Valor'] . '//' . $GETCOMMETH[1]['CorrAgente'] . '//OUT//' . $TransactionFTName)) {
                    $Exception_error = 'Error copying file.';
                }
                }else{
                    $error='FTP_CONFIG:No directory found.';
                }
            }
        }
    }
}